package com.self.smallma.myblogweb.web;

import com.self.smallma.myblogweb.entity.BlogEntity;
import com.self.smallma.myblogweb.service.BlogService;
import com.self.smallma.myblogweb.vo.BlogAndUserVo;
import com.self.smallma.myblogweb.vo.FirstPageBlogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class BlogShowController {

    @Autowired
    BlogService blogService;
    @GetMapping("/blog/{id}")
    public String blog(@PathVariable Long id, Model model){
        BlogAndUserVo blogEntity = blogService.getBlogAndUserById(id);


      if (blogEntity!=null){
          model.addAttribute("blog", blogEntity);
          return "blog";
      }else {
          model.addAttribute("message","查找失败");
          return "index";
      }
    }
}
